﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Midi;

namespace SkeletalTracking
{
    public static class GlobalVar
    {
        

        /// <summary>
        /// Static value protected by access routine.
        /// </summary>
        static int _globalValue;

        /// <summary>
        /// Access routine for global variable.
        /// </summary>
        public static int GlobalValue
        {
            get
            {
                return _globalValue;
            }
            set
            {
                _globalValue = value;
            }
        }


        /// <summary>
        /// Global static field.
        /// </summary>
        public static bool GlobalBoolean = true;
    }

    public static class MidiOutput
    {
        static OutputDevice _od;
        
        public static OutputDevice outputDevice
        {
            get
            {
                return _od;
            }
            set
            {
                _od = value;
                _od.Open();
            }
            
        }

        public static void playNote(float leftY, float rightY)
        {
            System.Console.WriteLine("rightY:");
            System.Console.WriteLine(rightY);
            int volume;
            int pitch = 0;
            int maxY = 80;
            int minY = 400;

            int blockSize = (minY - maxY) / ladders.Cmaj.Length;

            
            if (rightY < maxY)
            {
                volume = 127;
            }
            if (rightY > minY)
            {
                volume = 0;
            }
            else
            {
                volume = (127 -(int)(rightY / 5.35));
            }

            if (leftY < maxY)
            {
                pitch = 7;
            }
            if (leftY > minY)
            {
                pitch = 0;
            }
            if (leftY > maxY && leftY < minY)
            {
                pitch = 7- (((int)leftY - maxY) / blockSize);   
            }
            System.Console.WriteLine(pitch);
            outputDevice.SendNoteOn(Channel.Channel1, ladders.Cmaj[pitch], volume);

            //if (leftY > 220)
            //{
            //    outputDevice.SendNoteOn(Channel.Channel1, ladders.Cmaj[1], volume);
            //    System.Console.WriteLine("leftY:");
            //    System.Console.WriteLine(leftY);
            //}
            //if (leftY < 220)
            //{
            //    outputDevice.SendNoteOn(Channel.Channel1, ladders.Cmaj[6], volume);
            //    System.Console.WriteLine("leftY:");
            //    System.Console.WriteLine(leftY);
            //}

           
        }

        public static void close()
        {
            _od.Close();
        }
    }
    public static class ladders
    {

        public static Pitch[] Cmaj
        {
            get
            {
                Pitch[] notes = new Pitch[] { (Pitch)60, (Pitch)62, (Pitch)64, (Pitch)65, (Pitch)67, (Pitch)69, (Pitch)71, (Pitch)72};
                return notes;
            }
        }
    }
            
}
